import MySQLdb
from vle.vleApp.models import AnsweredQuiz, Student, FeedbackComment, Homework
from django.contrib.auth.models import User  					



def getMyComments(course, group):
    result=[]
    commentsList = FeedbackComment.objects.filter(course = course, group = group)
    if commentsList:
            for comment in commentsList:
                    result+=[[comment.comment,comment.category, comment.minGrade, comment.id]]
            return result
    else:
            return []

def getMyHomeworks(course, group):
    result=[]
    homeworksList = Homework.objects.filter(courseKey = course, groupKey = group).order_by('-date')
    if homeworksList:
            for homework in homeworksList:
                    result+=[[homework.subjects,homework.date,homework.id]]
            return result
    else:
            return []


def updateStudentSesionHours(userID, hours):
    student = Student.objects.filter(id = userID)[0]
    if student:
        student.sesionTime += hours
        student.save
        return True
    return False
    
def getStudentByUserID(userID):
    student = Student.objects.filter(id = userID)[0]
    if student:
        return student
    return False

def getUserMail(login):
    if Student.objects.filter(username = login)[0]:
        return Student.objects.filter(username = login)[0].email
    else:
        return ""